package sg.edu.nus.iss.vmcs.entity;

/*
 * Copyright 2003 ISS.
 * The contents contained in this document may not be reproduced in any
 * form or by any means, without the written permission of ISS, other
 * than for the purpose for which it has been supplied.
 *
 */


public abstract class Store1 {

	protected int size;

	protected StoreItem items[];
	
	public StoreItem[] getItems() {
		return items;
	}

	public void updateItem(StoreItem object){
		for (int i = 0; i < size; i++) {
			if (items[i] == null || items[i].getContent() == null)
				continue;
			if(object != null && items[i].getContent().equals(object.getContent()) ){
				items[i] = object;
			}
		}
	}
	
	public abstract void storeRecords();
	
	public StoreItem getItem(int idx) {
		if ((idx >= size) || (idx < 0))
            return null;
		return items[idx];
	}

	public int getStoreSize() {
		return size;
	}
	
	protected void setStoreSize(int size) {
		this.size = size;
		items = new StoreItem[size];
	}



	public void addItem(int idx,StoreItem object) {
		if ((idx >= size) || (idx < 0)){
			return;
		}
		items[idx] = object;
	}

	public StoreItem findStoreItem(StoreObject storeObject) {
		for (int i = 0; i < size; i++) {
			if (items[i] == null || items[i].getContent() == null)
				continue;
			if(storeObject != null && items[i].getContent().equals(storeObject) ){
				return items[i];
			}
		}
		return null;
	}
}
